<template>
    <view class="practice">
		<view style="height: 25px; width: 750rpx; background-color:transparent;"></view>
		<my-title :title="title" @back="back" :buttonflag="false"></my-title>
      <view class="practice_content">
      	<view class="content_title">
      		<text :class="['title_content', !active ? 'active' : '']" @click="theory">焊工专业理论课程</text>
      		<text :class="['title_content', active ? 'active' : '']" @click="practice">焊工专业实操课程</text>
      		<text></text>
      	</view>
      	<view class="content_list">
      		<list :lists="lists" @chapter-select="chapterSelect" ></list>
      	</view>
      </view>
    </view>
</template>

<script>
	import myTitle from '../../components/title.vue'
	import list from '../../components/courseList.vue'
	export default {
		data() {
			return {
				lists: [
				],
				active: false,
				title: '',
				token: '',
				cid: 2
			}
		},
		components: {list, myTitle},
		methods: {
			theory () {
				this.active = false
				this.cid = 2
				this.getChapter()
			},
			practice () {
				this.active = true
				this.cid = 4
				this.getChapter()
			},
			back () {
				uni.navigateTo({
					url: '/pages/index/index'
				})
			},
			chapterSelect (id) {
				uni.navigateTo({
					url: `/pages/training/ppt?cid=${id}&tit=${this.title}`
				})
			},
			getChapter () {
				uni.request({
					url: 'http://exam.tutestudio.net/api/student/chapter?cid=' + this.cid,
					method: 'GET',
					header: {
						token: this.token
					},
					success: (res) => {
						if (res.data.statusCode !== 200) {
							uni.showToast({
								title: res.data.errors,
								icon: 'none'
							})
						}
						this.lists = res.data.data
						console.log(this.lists)
					},
					fail(err) {
						uni.showToast({
							title: '接口参数有误！',
							icon: 'none'
						})
					}
				})
			}
		},
		onLoad: function (option) { //option为object类型，会序列化上个页面传递的参数
				this.title = option.title
				this.token = uni.getStorageSync('token')
				if (!this.token) {
					uni.navigateTo({
						url: '../loginpage/loginpage'
					})
					return;
				}
				this.getChapter()
		}
	}
</script>

<style lang="scss" scoped>
	.practice {
		width: 750rpx;
		height: 100vh;
		.practice_hearder {
			position: relative;
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			image {
				height: 50rpx;
				width: 50rpx;
				left: 18rpx;
				top: 26rpx;
				position: absolute;
			}
			text {
				font-size: 18px;
				position: absolute;
				left: 50%;
				transform: translateX(-50%);
			}
		}
		}
		.practice_content {
			width: 100%;
			margin-top: 20px;
			.content_title {
				height: 80rpx;
				width: 700rpx;
				display: flex;
				justify-content: space-between;
				line-height: 80rpx;
				.title_content {
					font-size: 17px;
					flex: 1;
					text-align: center;
					margin-left: 25rpx;
					color: black;
				}
				.active {
					color: #3C86FD;
					font-weight: 800  ;
					
				}
			}
			.content_list{
				margin: 20px 20px;
			}
		}
/* 	view {
		padding: 0px 8px;
	} */
	
	
</style>
